package cn.wolfcode.luowowo.small.service;

import cn.wolfcode.luowowo.small.domin.Goods;
import cn.wolfcode.luowowo.small.mapper.GoodsMapper;
import cn.wolfcode.luowowo.small.query.GoodsQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService{
  @Autowired
  private GoodsMapper goodsMapper;

  @Override
  public PageInfo query(GoodsQueryObject qo) {
    PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
    List<Goods> list = goodsMapper.selectForList(qo);
    return new PageInfo(list);

  }

  @Override
  public void updateGoodsNumById(Long goodsId) {
    goodsMapper.updateGoodsNumById(goodsId);
  }

  @Override
  public void addUserAndGoodsRelationById(Long goodsId, Long userId) {
    goodsMapper.addUserAndGoodsRelationById(goodsId,userId);
  }

  @Override
  public Goods selectById(Long goodsId) {
    return goodsMapper.selectByPrimaryKey(goodsId);
  }
}
